package cn.itcast.bos.web.action.system;

import cn.itcast.bos.domain.system.Menu;
import cn.itcast.bos.domain.system.User;
import cn.itcast.bos.service.system.MenuService;
import cn.itcast.bos.utils.BaseAction;
import com.opensymphony.xwork2.ActionContext;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;


import java.util.List;

@Controller
@Namespace("/")
@ParentPackage("json-default")
@Scope("prototype")
public class MenuAction extends BaseAction<Menu> {
   @Autowired
   private MenuService menuService;
    //查询所有菜单的方法
    @Action(value = "menu_findAll",results = {@Result(name="success",type = "json")})
    public String findAllMenu(){
        List<Menu> menus = menuService.findAll();
        //压入栈顶
        ActionContext.getContext().getValueStack().push(menus);
        return SUCCESS;
    }
    //保存菜单的操作
    @Action(value="menu_save",results = {@Result(name="success",type="redirect",location = "./pages/system/menu.html")})
    public String saveMenu(){
        menuService.save(model);
        return SUCCESS;
    }
    //通过判断不同的user来显示不同菜单的方法
    @Action(value = "menu_findByUser" ,results = {@Result(name="success",type = "json")})
    public  String findMenuByUser(){
        List<Menu> menus = menuService.findByUser();
        ActionContext.getContext().getValueStack().push(menus);
        return SUCCESS;
    }
}
